home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10114 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  44 lines

  1. Path: mozo.cc.purdue.edu!not-for-mail
  2. From: hrubin@b.stat.purdue.edu (Herman Rubin)
  3. Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
  4. Subject: Re: Access carry flag from C
  5. Date: 6 Mar 1996 04:34:29 -0500
  6. Organization: Purdue University Statistics Department
  7. Message-ID: <4hjm75$18u8@b.stat.purdue.edu>
  8. References: <4h1veoINNlns@anvil.ugrad.cs.ubc.ca> <fgrieu-0403961143580001@ppp78.micronet.fr> <4hhbt8$1d3o@b.stat.purdue.edu> <Dnssxu.JGy@cwi.nl>
  9. NNTP-Posting-Host: b.stat.purdue.edu
  10.  
  11. In article <Dnssxu.JGy@cwi.nl>, Dik T. Winter <dik@cwi.nl> wrote:
  12. >In article <4hhbt8$1d3o@b.stat.purdue.edu> hrubin@b.stat.purdue.edu (Herman Rubin) writes:
  13. > > In article <fgrieu-0403961143580001@ppp78.micronet.fr>,
  14. > > Franτois Grieu <fgrieu@micronet.fr> wrote:
  15.   
  16. > > >   if (x + yl < yl) ++yh; /* test for overflow on next line */
  17. > > >   yl += x;
  18. >...
  19. > > Notice that in the above code, each addition must be performed twice.
  20.  
  21. >Wrong.  Even a mediocre compiler will optimize this away.
  22.  
  23. Even if this is done, there are still two additions, as the comparison
  24. is normally done by an addition in hardware.  Add this to the overhead
  25. of the test, and much time is used.
  26.  
  27. > > BTW, there is a weakness in the code; ++yh can cause a carry, so
  28. > > another test is needed.  As testing is expensive, what is needed in
  29. > > this case is not a test for carry, but the ability to add the carry
  30. > > bit to something.
  31.  
  32. >But the code above also works on machines without carry bit.
  33.  
  34. This still affects the result.
  35.  
  36. On machines without the carry bit, an efficient mp routine would
  37. use a few less bits in the word, so that all these tests would
  38. not be needed.  One is rarely interested in EXACTLY double the
  39. precision provided by the hardware, just as one is rarely interested
  40. in exactly the precision of the hardware.
  41. -- 
  42. Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907-1399
  43. hrubin@stat.purdue.edu     Phone: (317)494-6054    FAX: (317)494-0558
  44.